#region Summary 

// 
// Owner : JackieHan 
// 
// Solution : LearnSolution 
// 
// Project : JackieHan.Popedom.HttpModule 
// 
// File : CustomerHttpModule.cs 
// 
// CopyRight : Copyright © 2009-2010 JackieHan Personal, All Rights Reserved 
// 
// Summary : 自定义的HttpModule 
// 
// History : 
//			2010-05-18 17:27:42	    Create 
// 

#endregion

#region Using 

using System;
using System.Collections.Generic;
using System.Web;

#endregion

namespace JackieHan.Popedom.HttpModule
{
    /// <summary> 
    /// 自定义的HttpModule 
    /// </summary> 
    public class CustomerHttpModule:IHttpModule
    {
        public event EventHandler ExposedEvent;

        public void Dispose()
        {
            
        }

        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
            context.EndRequest += new EventHandler(context_EndRequest);
        }

        void context_EndRequest(object sender, EventArgs e)
        {
            HttpApplication application = sender as HttpApplication;
            HttpContext context = application.Context;
            context.Response.Write("<hr><h1 style='color:#00f'>来自HttpModule的处理，请求结束</h1>");
        }

        private void OnExposedEvent(EventArgs eventArgs)
        {
            if (ExposedEvent != null)
                ExposedEvent(this, eventArgs);
        }

        void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = sender as HttpApplication;
            HttpContext context = application.Context;
            context.Response.Write("<h1 style='color:#00f'>来自HttpModule的处理，请求到达</h1><hr>");

            OnExposedEvent(new EventArgs());
        }
    }
}
